package com.gdufe.firesafe.model.vo;

import cn.hutool.core.bean.BeanUtil;
import com.gdufe.firesafe.model.entity.DeviceEntity;
import com.gdufe.firesafe.service.HouseService;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 消防设备表
 *
 * @author Liu
 * @email
 * @date 2024-03-25 20:54:21
 */
@Data
public class DeviceVO implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 消防设备id
	 */
	private Integer id;
	/**
	 * 所属房屋
	 */
	private String house;
	/**
	 * 是否可用
	 */
	private Boolean available;
	/**
	 * 设备类型（1-灭火器，2-烟雾探测器）
	 */
	private Integer type;
	/**
	 * 设备型号
	 */
	private String model;
	/**
	 * 生产厂商
	 */
	private String manufacturer;
	/**
	 * 购买日期
	 */
//	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date purchaseDate;
	/**
	 * 设备到期时间
	 */
	private Date expireDate;
	/**
	 * 上次检查日期
	 */
	private Date lastInspectionDate;
	/**
	 * 备注
	 */
	private String note;

	/**
	 * entity转vo，需要houseService
	 *
	 * @param deviceEntity
	 * @param houseService
	 * @return
	 */
	public static DeviceVO entityToVO(DeviceEntity deviceEntity, HouseService houseService){
		String address = houseService.getById(deviceEntity.getHouseId()).getAddress();
		return entityToVO(deviceEntity, address);
	}

	/**
	 * entity转vo，需要地址
	 * @param deviceEntity
	 * @param address
	 * @return
	 */
	public static DeviceVO entityToVO(DeviceEntity deviceEntity, String address){
		DeviceVO deviceVO = BeanUtil.copyProperties(deviceEntity, DeviceVO.class);
		deviceVO.setHouse(address);
		return deviceVO;
	}
}
